﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Microsoft.ApplicationBlocks.Data;
using System.Data;
using System.Data.SqlClient;
using System.IO;

public class DBClass:BaseServ
{
    int result;
	public DBClass()
	{
        result = 0;
    }
    #region functions
    public SqlConnection GetSqlConnection()
    {
        return new SqlConnection(dbConnString);
    }
    public DataSet GetAll()
    {
        DataSet ds = SqlHelper.ExecuteDataset(dbConnString,"");
        return ds;
    }
    public int Exec()
    {
        result = SqlHelper.ExecuteNonQuery(dbConnString, "");
        return result;
    }
    #endregion
    #region login
    public DataSet LoginUserInfo(string Username, string Password)
    {
        DataSet ds = SqlHelper.ExecuteDataset(dbConnString, "[LoginUserInfo]", Username, Password);
        return ds;
    }
    #endregion

    #region userinfo
    public DataSet GetAllUserInfo(int Id)
    {
        DataSet ds = SqlHelper.ExecuteDataset(dbConnString, "[GetAllUserInfo]", Id);
        return ds;
    }
    public int DeleteUserInfo(int Id)
    {
        result = SqlHelper.ExecuteNonQuery(dbConnString, "[DeleteUserInfo]",Id);
        return result;
    }
    public int InsertUserInfo(string Username, string Password, string FirstName, string LastName, string Email, bool IsEnabled, bool IsAdmin, string Phone)
    {
        object result = SqlHelper.ExecuteScalar(dbConnString, "[InsertUserInfo]", Username, Password, FirstName, LastName, Email, IsEnabled, IsAdmin, Phone);
        return Convert.ToInt32(result);
    }
    public int UpdateUserInfo(int Id,string Username, string Password, string FirstName, string LastName, string Email, bool IsEnabled, bool IsAdmin, string Phone)
    {
        object result = SqlHelper.ExecuteScalar(dbConnString, "[UpdateUserInfo]", Id, Username, Password, FirstName, LastName, Email, IsEnabled, IsAdmin, Phone);
        return Convert.ToInt32(result);
    }
    public int ChangeUserInfo(int Id, string FirstName, string LastName, string Email,  string Phone)
    {
        object result = SqlHelper.ExecuteScalar(dbConnString, "[ChangeUserInfo]", Id, FirstName, LastName, Email, Phone);
        return Convert.ToInt32(result);
    }
    public int ResetPassword(int Id, string Password)
    {
        object result = SqlHelper.ExecuteScalar(dbConnString, "[ResetPassword]", Id, Password);
        return Convert.ToInt32(result);
    }
    #endregion

    #region gallery
    public DataSet GetAllGallery(int Id)
    {
        DataSet ds = SqlHelper.ExecuteDataset(dbConnString, "[GetAllGallery]", Id);
        return ds;
    }
    public int DeleteGallery(int Id)
    {
        result = SqlHelper.ExecuteNonQuery(dbConnString, "[DeleteGallery]", Id);
        return result;
    }
    public int InsertGallery(string Name, string Image, string Description, int TypeId)
    {
        object result = SqlHelper.ExecuteScalar(dbConnString, "[InsertGallery]", Name, Image, Description, TypeId);
        return Convert.ToInt32(result);
    }
    public int UpdateGallery(int Id, string Name, string Image, string Description, int TypeId)
    {
        object result = SqlHelper.ExecuteScalar(dbConnString, "[UpdateGallery]", Id, Name, Image, Description, TypeId);
        return Convert.ToInt32(result);
    }
    public DataSet GetListGalleryImageByGalleryId(int GalleryId)
    {
        DataSet ds = SqlHelper.ExecuteDataset(dbConnString, "[GetListGalleryImageByGalleryId]", GalleryId);
        return ds;
    }
    public DataSet GetListGalleryImageById(int Id)
    {
        DataSet ds = SqlHelper.ExecuteDataset(dbConnString, "[GetListGalleryImageById]", Id);
        return ds;
    }
    public int InsertGalleryImage(string Image, string Note, int GalleryId)
    {
        object result = SqlHelper.ExecuteScalar(dbConnString, "[InsertGalleryImage]", Image, Note, GalleryId);
        return Convert.ToInt32(result);
    }
    public int UpdateGalleryImage(int Id, string Image, string Note, int GalleryId)
    {
        object result = SqlHelper.ExecuteScalar(dbConnString, "[UpdateGalleryImage]", Id, Image, Note, GalleryId);
        return Convert.ToInt32(result);
    }
    public int DeleteGalleryImage(int Id)
    {
        result = SqlHelper.ExecuteNonQuery(dbConnString, "[DeleteGalleryImage]", Id);
        return result;
    }
    #endregion

    #region Type
    public DataTable GetInfoTypeByTypeId(int TypeId)
    {
        DataSet ds = SqlHelper.ExecuteDataset(dbConnString, "GetInfoTypeByTypeId", TypeId);
        if (ds != null && ds.Tables.Count > 0)
        {
            return ds.Tables[0];
        }
        return null;
    }

    public DataTable GetAllType()
    {
        DataSet ds = SqlHelper.ExecuteDataset(dbConnString, "GetAllType");
        if (ds != null && ds.Tables.Count > 0)
        {
            return ds.Tables[0];
        }
        return null;
    }
    #endregion

    #region Development
    public DataTable GetListDevelopmentByTypeId(int TypeId)
    {
        DataSet ds = SqlHelper.ExecuteDataset(dbConnString, "GetListDevelopmentByTypeId", TypeId);
        if (ds != null && ds.Tables.Count > 0)
        {
            return ds.Tables[0];
        }
        return null;
    }

    public int UpdateDevelopment(string Development, int TypeId, int DevId)
    {
        return SqlHelper.ExecuteNonQuery(dbConnString, "UpdateDevelopment", Development, TypeId, DevId);
    }

    public int InsertDevelopment(string Development, int TypeId)
    {
        return SqlHelper.ExecuteNonQuery(dbConnString, "InsertDevelopment", Development, TypeId);
    }

    public int DeleteDevelopment(int DevId)
    {
        return SqlHelper.ExecuteNonQuery(dbConnString, "DeleteDevelopment", DevId);
    }

    public DataTable GetInfoDevelopmentById(int DevId)
    {
        DataSet ds = SqlHelper.ExecuteDataset(dbConnString, "GetInfoDevelopmentById", DevId);
        if (ds != null && ds.Tables.Count > 0)
        {
            return ds.Tables[0];
        }
        return null;
    }

    #endregion

    #region Deployment
    public DataTable GetListDeploymentByTypeId(int TypeId)
    {
        DataSet ds = SqlHelper.ExecuteDataset(dbConnString, "GetListDeploymentByTypeId", TypeId);
        if (ds != null && ds.Tables.Count > 0)
        {
            return ds.Tables[0];
        }
        return null;
    }

    public int UpdateDeployment(string Deployment, int TypeId, int DepId)
    {
        return SqlHelper.ExecuteNonQuery(dbConnString, "UpdateDeployment", Deployment, TypeId, DepId);
    }

    public int InsertDeployment(string Deployment, int TypeId)
    {
        return SqlHelper.ExecuteNonQuery(dbConnString, "InsertDeployment", Deployment, TypeId);
    }

    public int DeleteDeployment(int DepId)
    {
        return SqlHelper.ExecuteNonQuery(dbConnString, "DeleteDeployment", DepId);
    }

    public DataTable GetInfoDeploymentById(int DepId)
    {
        DataSet ds = SqlHelper.ExecuteDataset(dbConnString, "GetInfoDeploymentById", DepId);
        if (ds != null && ds.Tables.Count > 0)
        {
            return ds.Tables[0];
        }
        return null;
    }

    #endregion

    #region FactList
    public DataTable GetListFactListByTypeId(int TypeId)
    {
        DataSet ds = SqlHelper.ExecuteDataset(dbConnString, "GetListFactListByTypeId", TypeId);
        if (ds != null && ds.Tables.Count > 0)
        {
            return ds.Tables[0];
        }
        return null;
    }

    public int UpdateFactList(string FactListDescription, int TypeId, int FactListId)
    {
        return SqlHelper.ExecuteNonQuery(dbConnString, "UpdateFactList", FactListDescription, TypeId, FactListId);
    }

    public int InsertFactList(string FactListDescription, int TypeId)
    {
        return SqlHelper.ExecuteNonQuery(dbConnString, "InsertFactList", FactListDescription, TypeId);
    }

    public int DeleteFactList(int FactListId)
    {
        return SqlHelper.ExecuteNonQuery(dbConnString, "DeleteFactList", FactListId);
    }

    public DataTable GetInfoFactListById(int FactListId)
    {
        DataSet ds = SqlHelper.ExecuteDataset(dbConnString, "GetInfoFactListById", FactListId);
        if (ds != null && ds.Tables.Count > 0)
        {
            return ds.Tables[0];
        }
        return null;
    }

    #endregion

    #region PromotionImage
    public DataTable GetListPromotionImage(int TypeId)
    {
        DataSet ds = SqlHelper.ExecuteDataset(dbConnString, "GetListPromotionImage", TypeId);
        if (ds != null && ds.Tables.Count > 0)
        {
            return ds.Tables[0];
        }
        return null;
    }

    public int UpdatePromotionImage(string PromotionDescription, string Image, int TypeId, int PromotionId)
    {
        return SqlHelper.ExecuteNonQuery(dbConnString, "UpdatePromotionImage", PromotionDescription, Image, TypeId, PromotionId);
    }

    public int InsertPromotionImage(string PromotionDescription,string Image, int TypeId)
    {
        return SqlHelper.ExecuteNonQuery(dbConnString, "InsertPromotionImage", PromotionDescription, Image, TypeId);
    }

    public int DeletePromotionImage(int PromotionId)
    {
        return SqlHelper.ExecuteNonQuery(dbConnString, "DeletePromotionImage", PromotionId);
    }

    public DataTable GetInfoPromotionById(int PromoId)
    {
        DataSet ds = SqlHelper.ExecuteDataset(dbConnString, "GetInfoPromotionById", PromoId);
        if (ds != null && ds.Tables.Count > 0)
        {
            return ds.Tables[0];
        }
        return null;
    }

    #endregion

    #region Image Format

    public bool IsFormatImage(string ImageName)
    {
        string Extension = Path.GetExtension(ImageName);
        if (Extension == ".jpg" || Extension == ".jpeg" || Extension == ".png" || Extension == ".bmp" || Extension == ".gif")
        {
            return true;
        }
        return false;
    }
    #endregion

    #region DefaultValue

    public DataTable SelectDefaultIntroductionByPosId(int PosId)
    {
        DataSet ds = SqlHelper.ExecuteDataset(dbConnString, "SelectDefaultIntroductionByPosId", PosId);
        if (ds != null && ds.Tables.Count > 0)
        {
            return ds.Tables[0];
        }
        return null;
    }

    public DataTable SelectDetailByDafaultId(int DefaultId)
    {
        DataSet ds = SqlHelper.ExecuteDataset(dbConnString, "SelectDefaultIntroductionByPosId", DefaultId);
        if (ds != null && ds.Tables.Count > 0)
        {
            return ds.Tables[0];
        }
        return null;
    }

    #endregion
}